package models;

import javax.persistence.Entity;

import play.db.jpa.Model;

@Entity
public class UserConfig extends Model {
    
    public static final String KEY_SENSOR_MAX_TIME_DIFF_MS = "SENSOR_max_time_diff_ms";
    public static final String KEY_NODEAVERAGE_MAX_TIME_DIFF_MS = "NODEAVERAGE_max_time_diff_ms";

    public static final String TEMPERATURE_MAX_DIVERGENT = "TEMPERATURE_max_divergent";
    public static final String MOISTURE_MAX_DIVERGENT = "MOISTURE_max_divergent";
    public static final String TEMPERATURE_IR_MAX_DIVERGENT = "TEMPERATURE_max_divergent";
    public static final String AMBIENT_MAX_DIVERGENT = "AMBIENT_max_divergent";
    public static final String HUMIDITY_MAX_DIVERGENT = "HUMIDITY_max_divergent";
    public static final String MAX_DIVERGENT_KEY_EXT = "_max_divergent";

    public static final String TEMPERATURE_MAX_VALUE_USER = "TEMPERATURE_max_value_user";
    public static final String TEMPERATURE_MIN_VALUE_USER = "TEMPERATURE_min_value_user";
    public static final String MOISTURE_MAX_VALUE_USER = "MOISTURE_max_value_user";
    public static final String MOISTURE_MIN_VALUE_USER = "MOISTURE_min_value_user";
    public static final String TEMPERATURE_IR_MAX_VALUE_USER = "TEMPERATURE_max_value_user";
    public static final String TEMPERATURE_IR_MIN_VALUE_USER = "TEMPERATURE_min_value_user";
    public static final String AMBIENT_MAX_VALUE_USER = "AMBIENT_max_value_user";
    public static final String AMBIENT_MIN_VALUE_USER = "AMBIENT_min_value_user";
    public static final String HUMIDITY_MAX_VALUE_USER = "HUMIDITY_max_value_user";
    public static final String HUMIDITY_MIN_VALUE_USER = "HUMIDITY_min_value_user";
    public static final String MAX_VALUE_USER_KEY_EXT = "_max_value_user";
    public static final String MIN_VALUE_USER_KEY_EXT = "_min_value_user";

    private String propertyKey;
    private String propertyValue;
    private String description;

    protected UserConfig() {
    }

    public UserConfig(String propertyKey, String propertyValue, String description) {
        this.propertyKey = propertyKey;
        this.propertyValue = propertyValue;
        this.description = description;
    }

    public String getPropertyKey() {
        return propertyKey;
    }

    public String getPropertyValue() {
        return propertyValue;
    }

    public String getDescription() {
        return description;
    }

    public void setPropertyKey(String propertyKey) {
        this.propertyKey = propertyKey;
    }

    public void setPropertyValue(String propertyValue) {
        this.propertyValue = propertyValue;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public static UserConfig getProperty(String key) {
        // Returns NULL if empty
        return find("SELECT c FROM UserConfig c WHERE c.propertyKey=?1", key).first();
    }

    @Override
    public String toString() {
        return "Userconfig [propertyKey=" + propertyKey + " propertyValue=" + propertyValue + " description="
                + description + "}";
    }
}
